﻿<a href="https://html5css.ru/sql/sql_quickref.php" target="_blank">https://html5css.ru/sql/sql_quickref.php</a>

<!-- Start Document Outline -->

* [SQL Statement	Syntax](#sql-statementsyntax)
	* [AND / OR](#and--or)
	* [ALTER TABLE](#alter-table)
	* [AS (alias)](#as-alias)
	* [BETWEEN](#between)
	* [CREATE INDEX](#create-index)
	* [CREATE VIEW](#create-view)
	* [DELETE](#delete)
	* [DROP DATABASE](#drop-database)
	* [DROP INDEX](#drop-index)
	* [DROP TABLE](#drop-table)
	* [EXISTS](#exists)
	* [GROUP BY](#group-by)
	* [HAVING](#having)
	* [IN](#in)
	* [INSERT INTO](#insert-into)
	* [INNER JOIN](#inner-join)
	* [LEFT JOIN](#left-join)
	* [RIGHT JOIN](#right-join)
	* [FULL JOIN](#full-join)
	* [LIKE](#like)
	* [ORDER BY](#order-by)
	* [SELECT *](#select-)
	* [SELECT DISTINCT](#select-distinct)
	* [SELECT INTO](#select-into)
	* [SELECT TOP](#select-top)
	* [UNION](#union)
	* [UNION ALL](#union-all)
	* [UPDATE](#update)
	* [WHERE](#where)
	* [ul](#ul)
	* [ol](#ol)

<!-- End Document Outline -->
# SQL Statement	Syntax
## AND / OR
```sql
SELECT column_name(s)
FROM table_name
WHERE condition
AND|OR condition
```
## ALTER TABLE
```sql
ALTER TABLE table_name
ADD column_name datatype
or

ALTER TABLE table_name
DROP COLUMN column_name
```
## AS (alias)
```sql
SELECT column_name AS column_alias
FROM table_name
or

SELECT column_name
FROM table_name  AS table_alias
```
## BETWEEN
```sql
SELECT column_name(s)
FROM table_name
WHERE column_name
BETWEEN value1 AND value2
CREATE DATABASE	CREATE DATABASE database_name
CREATE TABLE	CREATE TABLE table_name
(
column_name1 data_type,
column_name2 data_type,
column_name3 data_type,
...
)

```
## CREATE INDEX
```sql
CREATE INDEX index_name
ON table_name (column_name)
or

CREATE UNIQUE INDEX index_name
ON table_name (column_name)
```
## CREATE VIEW
```sql
CREATE VIEW view_name AS
SELECT column_name(s)
FROM table_name
WHERE condition
```
## DELETE	
```sql
DELETE FROM table_name
WHERE some_column=some_value
or

DELETE FROM table_name
(Note: Deletes the entire table!!)

DELETE * FROM table_name
(Note: Deletes the entire table!!)
```
## DROP DATABASE
```sql
DROP DATABASE database_name
```
## DROP INDEX
```sql
DROP INDEX table_name.index_name (SQL Server)
DROP INDEX index_name ON table_name (MS Access)
DROP INDEX index_name (DB2/Oracle)
ALTER TABLE table_name
DROP INDEX index_name (MySQL)

```
## DROP TABLE
```sql
DROP TABLE table_name
```
## EXISTS
```sql
IF EXISTS (SELECT * FROM table_name WHERE id = ?)
BEGIN
--do what needs to be done if exists
END
ELSE
BEGIN
--do what needs to be done if not
END

```
## GROUP BY
```sql
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name

```
## HAVING
```sql
SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name
HAVING aggregate_function(column_name) operator value

```
## IN
```sql
SELECT column_name(s)
FROM table_name
WHERE column_name
IN (value1,value2,..)
```
## INSERT INTO
```sql
INSERT INTO table_name
VALUES (value1, value2, value3,....)
or

INSERT INTO table_name
(column1, column2, column3,...)
VALUES (value1, value2, value3,....)
```
## INNER JOIN
```sql
SELECT column_name(s)
FROM table_name1
INNER JOIN table_name2
ON table_name1.column_name=table_name2.column_name
```
## LEFT JOIN
```sql
SELECT column_name(s)
FROM table_name1
table_name2
ON table_name1.column_name=table_name2.column_name
```
## RIGHT JOIN
```sql
SELECT column_name(s)
FROM table_name1
RIGHT JOIN table_name2
ON table_name1.column_name=table_name2.column_name

```
## FULL JOIN
```sql
SELECT column_name(s)
FROM table_name1
FULL JOIN table_name2
ON table_name1.column_name=table_name2.column_name
```
## LIKE
```sql
SELECT column_name(s)
FROM table_name
WHERE column_name LIKE pattern
```
## ORDER BY	
```sql
SELECT column_name(s)
FROM table_name
ORDER BY column_name [ASC|DESC]
SELECT	SELECT column_name(s)
FROM table_name
```
## SELECT *	
```sql
SELECT *
FROM table_name
```
## SELECT DISTINCT
```sql
SELECT DISTINCT column_name(s)
FROM table_name
```
## SELECT INTO
```sql
SELECT *
INTO new_table_name [IN externaldatabase]
FROM old_table_name
or

SELECT column_name(s)
INTO new_table_name [IN externaldatabase]
FROM old_table_name
```
## SELECT TOP
```sql
SELECT TOP number|percent column_name(s)
FROM table_name
TRUNCATE TABLE	TRUNCATE TABLE table_name
```
## UNION
```sql
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
```
## UNION ALL
```sql
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
```
## UPDATE
```sql
UPDATE table_name
SET column1=value, column2=value,...
WHERE some_column=some_value
```
## WHERE
```sql
SELECT column_name(s)
FROM table_name
WHERE column_name operator value
```
    